package com.atguigu.java;

/**
 * 例子：创建三个窗口卖票，总票数为100张,使用Runnable接口的方式
 */
class Window1 implements Runnable {

    private  int ticket = 100;

    @Override
    public void run() {
        while (true) {
            if (ticket > 0) {
                System.out.println(Thread.currentThread().getName() + "买票，票号为：" + ticket);
                ticket--;
            } else {
                break;
            }
        }
    }
}

public class WindowTest1 {
    public static void main(String[] args) {
        Window1 window = new Window1();

        Thread w = new Thread(window);
        Thread w2 = new Thread(window);
        Thread w3 = new Thread(window);

        w.start();
        w2.start();
        w3.start();
    }
}
